Check the comparison result of AWS CLI with colordiff command

Check the comparison result of AWS CLI with colordiff command

Clock Icon2017.09.20

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

When we use the AWS CLI command "Describe", the diff command is used to make comparisons. In this post, we introduce the colordiff commmand which highlights the differences using colours.

Install

On Macs, colordiff can be installed using brew.

brew install colordiff

Colordiff is also available as a package on Linux/BSD.

colordiff | Availability of colordiff with your Linux/BSD distribution

Let's use colordiff

In the previous post, we checked the difference between the existing DB instance and the restored DB instance using diff. This time, we check the result using colordiff.

【Amazon RDS】Restoring From a DB Snapshot with AWS CLI

default

colordiff

-u option (unified output format)

Display with the difference with [-] and [+] symbols.

  -u  -U NUM  --unified[=NUM]  Output NUM (default 3) lines of unified context.
    --label LABEL  Use LABEL instead of file name.
    -p  --show-c-function  Show which C function each change is in.
    -F RE  --show-function-line=RE  Show the most recent line matching RE.

colordiff-u

-c option (context output format)

Lines with changes are displayed. A few neighbouring lines before and after the changes are also shown for easier reference. Changes are indicated by [!].

  -c  -C NUM  --context[=NUM]  Output NUM (default 3) lines of copied context.

colordiff-c

-y option (side by side format)

The output is presented side-by-side.

  -y  --side-by-side  Output in two columns.
    -W NUM  --width=NUM  Output at most NUM (default 130) print columns.
    --left-column  Output only the left column of common lines.
    --suppress-common-lines  Do not output common lines.

colordiff-y

Comparisons are easy to make because the output is displayed side-by-side. If we want to display more print columns, we use the-w option, and if we only want to output the difference, we use the --suppress-common-lines option.

TIPS

You can pipe to less -Rcommand.

colordiff -u file1 file2 | less -R

Conclusion

Colordiff displays the output with colours so we can easily compare the results of executing AWS CLIs. We recommend the use of colordiff for convenience.

References

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.